package com.fyy.socket.tcp.upload;

import com.fyy.socket.socketServer.SocketServer;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author fyy
 * @Description 文件上传服务器端
 * @Date 2020/12/15 15:15
 */
public class UpServer {

    public static void main(String[] args) throws IOException {
        ServerSocket socketServer = new ServerSocket(8088);
        Socket socket = socketServer.accept();
        String dFilePath = "F:\\test2.txt";
        try ( //创建文件输入输出流
              BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
              BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dFilePath));
        ){
            //读取文件
            byte[] buf = new byte[1024];
            int len;
            while ((len = bis.read(buf)) != -1){
                bos.write(buf,0,len);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
